/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "gmock/gmock-actions.h"
#include "mockcpp/mockcpp.hpp"
#include "JsonFileTool.h"
#include "ObjectStorageBackupJob.h"

class ObjectStorageBackupJobTest : public testing::Test {
public:
    void SetUp() {};
    void TearDown()
    {
        GlobalMockObject::verify();
    };
};

class StubBackup : public FS_Backup::Backup {
public:
    explicit StubBackup(const BackupParams& backupParams) : Backup(backupParams)
    {}

    BackupRetCode Start() override
    {
        return BackupRetCode::SUCCESS;
    }
    BackupRetCode Abort() override
    {
        return BackupRetCode::SUCCESS;
    }
    BackupRetCode Destroy() override
    {
        return BackupRetCode::SUCCESS;
    }
    BackupRetCode Enqueue(std::string controlFile) override
    {
        return BackupRetCode::SUCCESS;
    }
    BackupPhaseStatus GetStatus() override
    {
        return BackupPhaseStatus::COMPLETED;
    }
    BackupStats GetStats() override
    {
        BackupStats result;
        return result;
    }
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> GetFailedDetails() override
    {
        std::unordered_set<FailedRecordItem, FailedRecordItemHash> result;
        return result;
    }
};

/*
 * 用例名称：各个任务阶段入口测试
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ExternalUniversalInterfaceTest)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetBackupJobInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CheckBackupJobTypeInner)
        .stubs()
        .will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::PrerequisiteJobInner)
        .stubs()
        .will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GenerateSubJobInner)
        .stubs()
        .will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::ExecuteSubJobInner)
        .stubs()
        .will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::PostJobInner)
        .stubs()
        .will(returnValue(Module::SUCCESS));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    auto info = std::make_shared<JobCommonInfo>();
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.SetJobInfo(info);

    EXPECT_EQ(backupjob.CheckBackupJobType(), Module::SUCCESS);
    EXPECT_EQ(backupjob.PrerequisiteJob(), Module::SUCCESS);
    EXPECT_EQ(backupjob.GenerateSubJob(), Module::SUCCESS);
    EXPECT_EQ(backupjob.ExecuteSubJob(), Module::SUCCESS);
    EXPECT_EQ(backupjob.PostJob(), Module::SUCCESS);
}

/*
 * 用例名称：获取任务信息
 * 前置条件：无
 * check点：获取任务信息成功
 */
TEST_F(ObjectStorageBackupJobTest, GetBackupJobInfoSuccess)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    auto info = std::make_shared<JobCommonInfo>();
    auto data = std::make_shared<AppProtect::BackupJob>();
    info->SetJobInfo(data);
    backupjob.SetJobInfo(info);

    EXPECT_EQ(backupjob.GetBackupJobInfo(), true);
}

/*
 * 用例名称：获取任务信息
 * 前置条件：无
 * check点：获取任务信息失败
 */
TEST_F(ObjectStorageBackupJobTest, GetBackupJobInfoFailed)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    auto info = std::make_shared<JobCommonInfo>();
    backupjob.SetJobInfo(info);

    EXPECT_EQ(backupjob.GetBackupJobInfo(), false);
}

/*
 * 用例名称：检查任务类型
 * 前置条件：无
 * check点：检查任务类型成功
 */
TEST_F(ObjectStorageBackupJobTest, CheckBackupJobTypeInner)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::InitJobInfo)
        .stubs()
        .will(returnValue(true))
        .then(returnValue(false));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::NeedChangeIncToFull)
        .stubs()
        .will(returnValue(false))
        .then(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();

    backupjob.m_backupJobPtr->jobParam.backupType = AppProtect::BackupJobType::INCREMENT_BACKUP;
    EXPECT_EQ(backupjob.CheckBackupJobTypeInner(), Module::SUCCESS);
    backupjob.m_backupJobPtr->jobParam.backupType = AppProtect::BackupJobType::FULL_BACKUP;
    EXPECT_EQ(backupjob.CheckBackupJobTypeInner(), Module::SUCCESS);
    backupjob.m_backupJobPtr->jobParam.backupType = AppProtect::BackupJobType::INCREMENT_BACKUP;
    EXPECT_EQ(backupjob.CheckBackupJobTypeInner(), Module::FAILED);
    EXPECT_EQ(backupjob.CheckBackupJobTypeInner(), Module::FAILED);
}

/*
 * 用例名称：初始化任务详细信息
 * 前置条件：无
 * check点：初始化任务详细信息成功
 */
TEST_F(ObjectStorageBackupJobTest, InitJobInfo)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetAuthExtendInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::InitObjectStorageInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::InitMetaDataCacheBackupFs)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::InitRepoPaths)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_backupJobPtr->jobParam.backupType = AppProtect::BackupJobType::PERMANENT_INCREMENTAL_BACKUP;
    backupjob.m_authInfo.storageType = "2";

    EXPECT_EQ(backupjob.InitJobInfo(), true);
}

/*
 * 用例名称：获取对象存储注册信息
 * 前置条件：无
 * check点：获取对象存储注册信息成功
 */
TEST_F(ObjectStorageBackupJobTest, GetAuthExtendInfo)
{
    MOCKER_CPP(&Module::JsonHelper::JsonStringToStruct<OBSPlugin::ObjectStorageAuthExtendInfo>)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();

    EXPECT_EQ(backupjob.GetAuthExtendInfo(), true);
}

/*
 * 用例名称：获取保护桶及前缀信息
 * 前置条件：无
 * check点：获取保护桶及前缀信息成功
 */
TEST_F(ObjectStorageBackupJobTest, InitObjectStorageInfo)
{
    MOCKER_CPP(&Module::JsonHelper::JsonStringToJsonValue)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&Module::JsonHelper::JsonStringToStruct<OBSPlugin::OBSBackupAdvParam>)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_jobCtrlPhase = OBSPlugin::JOB_CTRL_PHASE_PREJOB;
    backupjob.m_backupJobPtr->protectObject.extendInfo = R"(
        {"bucketList":"[{\"name\":\"bucket1\",\"prefix\":[\"\uffe5%\"]}]"})";

    EXPECT_EQ(backupjob.InitObjectStorageInfo(), true);
}

/*
 * 用例名称：prefix子串去重功能测试
 * 前置条件：无
 * check点：所有重复子串都被去除
 */
TEST_F(ObjectStorageBackupJobTest, DeduplicatePrefixs)
{
    const std::vector<std::string> testPrefixs {"b", "a", "abc", "ab", "bcde", "bcd", "c"};
    const std::vector<std::string> expectDeduplicatePrefixs {"a", "b", "c"};

    OBSPlugin::ObjectStorageBackupJob backupjob;
    auto result = backupjob.DeduplicatePrefixs(testPrefixs);
    ASSERT_EQ(result.size(), expectDeduplicatePrefixs.size());
    for (std::size_t i = 0; i < result.size(); ++i) {
        EXPECT_EQ(result[i], expectDeduplicatePrefixs[i]);
    }
}

/*
 * 用例名称：仓文件系统初始化成功
 * 前置条件：无
 * check点：正确获取数据仓、元数据仓、cache仓文件系统
 */
TEST_F(ObjectStorageBackupJobTest, InitMetaDataCacheBackupFsSuccess)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    StorageRepository dataFs;
    dataFs.repositoryType = RepositoryDataType::DATA_REPOSITORY;
    dataFs.extendInfo = R"({"esn":"123"})";
    dataFs.path.emplace_back("/abc");
    backupjob.m_backupJobPtr->repositories.emplace_back(dataFs);
    StorageRepository cacheFs;
    cacheFs.repositoryType = RepositoryDataType::CACHE_REPOSITORY;
    cacheFs.path.emplace_back("/def/1");
    backupjob.m_backupJobPtr->repositories.emplace_back(cacheFs);
    StorageRepository metaFs;
    metaFs.repositoryType = RepositoryDataType::META_REPOSITORY;
    metaFs.path.emplace_back("/ghi/1");
    backupjob.m_backupJobPtr->repositories.emplace_back(metaFs);

    EXPECT_EQ(backupjob.InitMetaDataCacheBackupFs(), true);
}

/*
 * 用例名称：仓路径初始化成功
 * 前置条件：无
 * check点：正确获取数据仓、元数据仓、cache仓路径
 */
TEST_F(ObjectStorageBackupJobTest, InitRepoPathsSuccess)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_protectedOBS.advParms.m_aggregateSwitch = "false";
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    StorageRepository dataFs;
    dataFs.extendInfo = R"({"esn":"123"})";
    dataFs.path.emplace_back("/abc");
    backupjob.m_multiDataFsList.emplace_back(dataFs);
    backupjob.m_cacheFs.path.emplace_back("/def/1");
    backupjob.m_metaFs.path.emplace_back("/ghi/1");

    EXPECT_EQ(backupjob.InitRepoPaths(), true);

    EXPECT_EQ(backupjob.m_dataFsPathMap["123"], "/abc");
    EXPECT_EQ(backupjob.m_cacheFsPath, "/def/1");
    EXPECT_EQ(backupjob.m_metaFsPath, "/ghi/1");
}

/*
 * 用例名称：仓路径初始化失败
 * 前置条件：无
 * check点：数据仓路径获取失败
 */
TEST_F(ObjectStorageBackupJobTest, InitRepoPathsFailed)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_protectedOBS.advParms.m_aggregateSwitch = "false";
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    StorageRepository dataFs1;
    dataFs1.extendInfo = R"({"esn":"123"})";
    dataFs1.path.emplace_back("/aaa");
    backupjob.m_multiDataFsList.emplace_back(dataFs1);
    backupjob.m_cacheFs.path.emplace_back("/aaa/1");
    backupjob.m_metaFs.path.emplace_back("/aaa/2");
    StorageRepository dataFs2;
    dataFs2.extendInfo = R"({"esn":"123"})";
    dataFs2.path.emplace_back("/aaa");
    backupjob.m_multiDataFsList.emplace_back(dataFs2);
    backupjob.m_cacheFs.path.emplace_back("/bbb/1");
    backupjob.m_metaFs.path.emplace_back("/bbb/2");

    EXPECT_EQ(backupjob.InitRepoPaths(), false);
}

/*
 * 用例名称：需要增量转全量
 * 前置条件：无
 * check点：返回false
 */
TEST_F(ObjectStorageBackupJobTest, NeedChangeIncToFull)
{
    MOCKER(JsonFileTool::ReadFromFile<OBSPlugin::ObjectStorageBackupRecord>)
        .stubs()
        .will(returnValue(false))
        .then(returnValue(true));

    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::IsProtectedObjectsChanged)
        .stubs()
        .will(returnValue(true))
        .then(returnValue(false));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_backupJobPtr->jobParam.backupType == AppProtect::BackupJobType::INCREMENT_BACKUP;

    EXPECT_EQ(backupjob.NeedChangeIncToFull(), true);
    EXPECT_EQ(backupjob.NeedChangeIncToFull(), true);
}

/*
 * 用例名称：前置任务主流程
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, PrerequisiteJobInner)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::InitJobInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER(OBSPlugin::CreateDirectory)
        .stubs()
        .will(returnValue(true));
    MOCKER(OBSPlugin::Remove)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CreateSharedResources)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::UpdateGeneralResource)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_dataFsPathMap.emplace("123", "/abc");

    EXPECT_EQ(backupjob.PrerequisiteJobInner(), Module::SUCCESS);
}

/*
 * 用例名称：生成子任务主流程
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, GenerateSubJobInner)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetPrevBackupCopyInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::InitJobInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER(Module::JsonHelper::StructToJsonString<OBSPlugin::ObjectStorageBackupSubJob>)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CreateSubTask,
        int(OBSPlugin::ObjectStorageBackupJob::*)(const SubJob&))
        .stubs()
        .will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CreateBackupJobTeardownTask)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::WriteBackupObjectInfoToFile)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_backupJobPtr->jobParam.backupType == AppProtect::BackupJobType::FULL_BACKUP;
    backupjob.m_protectedOBS.advParms.m_multiNodeBackupSwitch = "false";
    backupjob.m_dataFsPathMap.emplace("123", "/abc");
    OBSPlugin::OBSProtectSubObject object;
    object.prefixs.emplace_back("prefix1");
    backupjob.m_protectedOBS.obsProtectSubObjectList.emplace_back(object);

    EXPECT_EQ(backupjob.GenerateSubJobInner(), Module::SUCCESS);
}

/*
 * 用例名称：生成落盘任务信息主流程
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, CreateBackupJobTeardownTask)
{
    MOCKER(Module::JsonHelper::StructToJsonString<OBSPlugin::ObjectStorageBackupSubJob>)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CreateSubTask,
        int(OBSPlugin::ObjectStorageBackupJob::*)(const SubJob&))
        .stubs()
        .will(returnValue(Module::SUCCESS));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();

    EXPECT_EQ(backupjob.CreateBackupJobTeardownTask(), true);
}

/*
 * 用例名称：执行子任务主流程
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ExecuteSubJobInner)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::InitJobInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::ExecutePrefixScanSubJob)
        .stubs()
        .will(returnValue(Module::SUCCESS));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    OBSPlugin::ObjectStorageBackupSubJob subJob;
    subJob.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_PREFIX_SCAN_PHASE;
    backupjob.m_subJobInfo = std::make_shared<SubJob>();
    ASSERT_EQ(Module::JsonHelper::StructToJsonString(subJob, backupjob.m_subJobInfo->jobInfo), true);

    EXPECT_EQ(backupjob.ExecuteSubJobInner(), Module::SUCCESS);
}

/*
 * 用例名称：执行扫描子任务主流程
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ExecutePrefixScanSubJob)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetPrevBackupInfo)
        .stubs()
        .will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetSharedResources)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::HoldScanner)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::StartScanner)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::MonitorScanner)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CreateBackupCopyMetaTask)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&ScanMgr::ReleaseRunningTask)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CreateBackupJobTaskToCreateFurtherSubTasks)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    OBSPlugin::ObjectStorageBackupSubJob subJob;
    subJob.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_PREFIX_SCAN_PHASE;
    subJob.prefixInfo.emplace_back(OBSPlugin::PrefixInfo());

    EXPECT_EQ(backupjob.ExecutePrefixScanSubJob(subJob), Module::SUCCESS);
}

/*
 * 用例名称：执行子任务主流程
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, HoldScanner)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_subJobInfo = std::make_shared<SubJob>();

    EXPECT_NO_THROW(backupjob.HoldScanner());
}

/*
 * 用例名称：启动扫描成功
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, StartScannerSuccess)
{
    MOCKER(OBSPlugin::RecurseCreateDirectory)
        .stubs()
        .will(returnValue(true));
    MOCKER(OBSPlugin::GetDeployType)
        .stubs()
        .will(returnValue(std::string("d0")));
    MOCKER_CPP(&Module::ConfigReader::getInt)
        .stubs()
        .will(returnValue(0));
    MOCKER_CPP(&Module::ConfigReader::getString)
        .stubs()
        .will(returnValue(std::string()));
    MOCKER_CPP(&ScanMgr::Initiate)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&ScanMgr::StartScan)
        .stubs()
        .will(returnValue(SCANNER_STATUS::SUCCESS));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::UpdateScanStatsResource)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    OBSPlugin::PrefixInfo prefixInfo;

    EXPECT_EQ(backupjob.StartScanner(prefixInfo), true);
}

/*
 * 用例名称：获得扫描生成文件相对目录
 * 前置条件：无
 * check点：返回目录相对路径
 */
TEST_F(ObjectStorageBackupJobTest, GetScanGenFileRelativeDir)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    OBSPlugin::PrefixInfo prefixInfo;
    prefixInfo.bucketName = "bucket1";
    prefixInfo.subPrefixs.emplace_back("/abcdefgh");

    EXPECT_EQ(backupjob.GetScanGenFileRelativeDir(prefixInfo), std::string("/bucket1/11399945197653540113/"));
}

/*
 * 用例名称：初始化扫描配置成功
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, FillScanConfig)
{
    MOCKER_CPP(&OBSPlugin::GetDeployType)
        .stubs()
        .will(returnValue(std::string("d0")))
        .then(returnValue(std::string("d1")));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::IsFullBackup)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&Module::ConfigReader::getInt)
        .stubs()
        .will(returnValue(0));
    MOCKER_CPP(&Module::ConfigReader::getString)
        .stubs()
        .will(returnValue(std::string()));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_protectedOBS.advParms.m_isBackupAcl = "true";
    OBSPlugin::PrefixInfo prefixInfo;
    ScanConfig scanConfig;

    EXPECT_NO_THROW(backupjob.FillScanConfig(prefixInfo, scanConfig));
    EXPECT_NO_THROW(backupjob.FillScanConfig(prefixInfo, scanConfig));
    void* usrData;
    const std::string controlFilePath;
    EXPECT_NO_THROW(scanConfig.scanResultCb(usrData, controlFilePath));
    EXPECT_NO_THROW(scanConfig.deleteCtrlCb(usrData, controlFilePath));
}

/*
 * 用例名称：扫描状态异常上报扫描状态
 * 前置条件：无
 * check点：正确获取对应错误码
 */
TEST_F(ObjectStorageBackupJobTest, ReportScannerStatusSuccess)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    const OBSPlugin::ObjectStorageNativeScanStatistics scanStatistics {};
    AppProtect::SubJobStatus::type jobStatus = AppProtect::SubJobStatus::type::FAILED;
    std::string jobLogLabel;
    int jobProgress = 0;

    EXPECT_NO_THROW(backupjob.ReportScannerStatus(scanStatistics, jobStatus, jobLogLabel, jobProgress));
    jobStatus = AppProtect::SubJobStatus::COMPLETED;
    EXPECT_NO_THROW(backupjob.ReportScannerStatus(scanStatistics, jobStatus, jobLogLabel, jobProgress));
}

/*
 * 用例名称：监控scanner执行
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, MonitorScanner)
{
    MOCKER_CPP(&ScanMgr::GetScanStatus)
        .stubs()
        .will(returnValue(SCANNER_STATUS::SCAN_IN_PROGRESS))
        .then(returnValue(SCANNER_STATUS::COMPLETED));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::UpdateScannerStatistics)
        .stubs()
        .will(ignoreReturnValue());
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CreateSubTasksFromCtrlFile)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::UpdateScanStatsResource)
        .stubs()
        .will(returnValue(true));
    MOCKER(sleep)
        .stubs()
        .will(ignoreReturnValue());

    OBSPlugin::ObjectStorageBackupJob backupjob;
    OBSPlugin::PrefixInfo prefixInfo;
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;

    EXPECT_EQ(backupjob.MonitorScanner(prefixInfo, "esn", jobStatus, jobLogLabel, jobProgress), true);
}

/*
 * 用例名称：生成备份子任务
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, CreateSubTasksFromCtrlFile)
{
    std::vector<std::string> srcFileList {"/ctrlfile1"};
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::checkFilePathAndGetSrcFileList)
        .stubs()
        .with(any(), any(), any(), outBound(srcFileList))
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::IsValidCtrlFile)
        .stubs()
        .will(returnValue(true));
    MOCKER(OBSPlugin::CopyFile)
        .stubs()
        .will(ignoreReturnValue());
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::InitSubJobInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CheckAndRetryCreateSubTask)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    const OBSPlugin::PrefixInfo prefixInfo;

    EXPECT_EQ(backupjob.CreateSubTasksFromCtrlFile(prefixInfo, "esn", 0), true);
}

/*
 * 用例名称：创建拷贝元数据子任务
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, CreateBackupCopyMetaTask)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CreateSubTask,
        int(OBSPlugin::ObjectStorageBackupJob::*)(const SubJob&))
        .stubs()
        .will(returnValue(Module::SUCCESS));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    OBSPlugin::PrefixInfo prefixInfo;

    EXPECT_EQ(backupjob.CreateBackupCopyMetaTask(prefixInfo, "metaPath"), true);
}

/*
 * 用例名称：创建拷贝元数据子任务
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, InitSubJobInfo)
{
    MOCKER(Module::JsonHelper::StructToJsonString<OBSPlugin::ObjectStorageBackupSubJob>)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_dataFsPathMap.emplace("123", "/abc");
    OBSPlugin::PrefixInfo prefixInfo;
    const std::string ctrlFile;
    SubJob subJob;

    EXPECT_EQ(backupjob.InitSubJobInfo(prefixInfo, ctrlFile, "esn", subJob), true);
}

/*
 * 用例名称：创建拷贝元数据子任务
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ExecuteDataCopySubJob)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetSharedResources)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::StartBackup)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::MonitorBackup)
        .stubs()
        .will(returnValue(OBSPlugin::ObjectStorageBackupJob::MONITOR_BACKUP_RES_TYPE::MONITOR_BACKUP_RES_TYPE_SUCCESS));

    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CreateSubTask,
        int(OBSPlugin::ObjectStorageBackupJob::*)(const SubJob&))
        .stubs()
        .will(returnValue(Module::SUCCESS));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    OBSPlugin::ObjectStorageBackupSubJob subJob;
    backupjob.m_subJobInfo = std::make_shared<SubJob>();

    EXPECT_EQ(backupjob.ExecuteDataCopySubJob(subJob), Module::SUCCESS);
}

/*
 * 用例名称：初始化备份配置
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, FillBackupConfig)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetSharedResources)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_dataFsPathMap.emplace("123", "/abc");

    OBSPlugin::ObjectStorageBackupSubJob backupSubJob;
    backupSubJob.prefixInfo.emplace_back(OBSPlugin::PrefixInfo());
    BackupParams backupParams;

    EXPECT_NO_THROW(backupjob.FillBackupConfig(backupSubJob, backupParams));
}

TEST_F(ObjectStorageBackupJobTest, FillAggregateBackupCommonParams)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_protectedOBS.advParms.m_maxSizeAfterAggregate = "1";
    backupjob.m_protectedOBS.advParms.m_maxSizeToAggregate = "1";

    BackupParams backupParams;
    EXPECT_NO_THROW(backupjob.FillAggregateBackupCommonParams(backupParams));
}

/*
 * 用例名称：初始化备份配置
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, MonitorBackup)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::UpdateBackupStatistics)
        .stubs()
        .will(returnValue(true));
    MOCKER(sleep)
        .stubs()
        .will(ignoreReturnValue());

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    BackupParams backupParams;
    backupjob.m_backup = std::make_unique<StubBackup>(backupParams);

    BackupStats backupStatistics;
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;
    EXPECT_EQ(
        backupjob.MonitorBackup(backupStatistics, jobStatus, jobLogLabel, jobProgress),
        OBSPlugin::ObjectStorageBackupJob::MONITOR_BACKUP_RES_TYPE::MONITOR_BACKUP_RES_TYPE_SUCCESS);
}

/*
 * 用例名称：监控流程处理
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, HandleMonitorStuck)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::UpdateBackupStatistics)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    BackupParams backupParams;
    backupjob.m_backup = std::make_unique<StubBackup>(backupParams);

    BackupStats backupStatistics;
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;
    EXPECT_NO_THROW(backupjob.HandleMonitorStuck(backupStatistics, jobStatus, jobLogLabel, jobProgress));
    EXPECT_NO_THROW(backupjob.HandleMonitorComplete(jobStatus, jobLogLabel, jobProgress));
    EXPECT_NO_THROW(backupjob.HandleMonitorFailed(jobStatus, jobLogLabel));
    EXPECT_NO_THROW(backupjob.HandleMonitorAborted(jobStatus, jobLogLabel));
}

/*
 * 用例名称：上报备份模块运行信息
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, UpdateBackupStatistics)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::UpdateBackupSubTaskStatistics)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::NodeLevelTaskInfo::CanSendLogReportToPM)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::LockBackupStatsResource)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetBackupStatsResource)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::UpdateBackupStatsResource)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::UnlockBackupStatsResource)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::NodeLevelTaskInfo::UpdateLogReportTimeToPM)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::ReportBackupRunningStatus)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    BackupStats backupStatistics;

    EXPECT_EQ(backupjob.UpdateBackupStatistics(backupStatistics), true);
}

/*
 * 用例名称：上报备份模块运行信息
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ReportBackupRunningStatus)
{
    MOCKER(OBSPlugin::GetFileListInDirectory)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::ReadBackupStatsFromFile)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();

    EXPECT_EQ(backupjob.ReportBackupRunningStatus(), true);
}

/*
 * 用例名称：上报备份状态
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ReportBackupStatus)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();

    SubJobStatus::type jobStatus = SubJobStatus::FAILED;
    std::string jobLogLabel;

    EXPECT_NO_THROW(backupjob.ReportBackupStatus(jobStatus, jobLogLabel));
    backupjob.m_backupStatus = BackupPhaseStatus::FAILED_NOACCESS;
    EXPECT_NO_THROW(backupjob.ReportBackupStatus(jobStatus, jobLogLabel));
    backupjob.m_backupStatus = BackupPhaseStatus::FAILED_NOSPACE;
    EXPECT_NO_THROW(backupjob.ReportBackupStatus(jobStatus, jobLogLabel));
    backupjob.m_backupStatus = BackupPhaseStatus::FAILED_PROT_SERVER_NOTREACHABLE;
    EXPECT_NO_THROW(backupjob.ReportBackupStatus(jobStatus, jobLogLabel));
    backupjob.m_backupStatus = BackupPhaseStatus::FAILED_SEC_SERVER_NOTREACHABLE;
    EXPECT_NO_THROW(backupjob.ReportBackupStatus(jobStatus, jobLogLabel));
}

TEST_F(ObjectStorageBackupJobTest, WriteBackupCopyToFile)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    std::string metaFileFullPath = "/home/1.txt";
    OBSPlugin::ObjectStorageLastCopyDetails backupCopy;
    backupCopy.m_isBackupAcl = "true";
    EXPECT_EQ(backupjob.WriteBackupCopyToFile(metaFileFullPath, backupCopy), true);
    OBSPlugin::Remove(metaFileFullPath);
}
/*
 * 用例名称：执行落盘副本信息子任务
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ExecuteTeardownSubJob)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetSharedResources)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::WriteBackupCopyToFile)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetSharedResources)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CalculateJobStats)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::ReportBackupCompletionStatus)
        .stubs()
        .will(returnValue(true));
    MOCKER(FS_Backup::BackupMgr::MergedbFile)
        .stubs()
        .will(returnValue(0));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_protectedOBS.advParms.m_aggregateSwitch = "true";
    backupjob.m_metaFs.path.emplace_back("/");
    backupjob.m_metaFsPathMap.emplace("123", "abc");
    
    EXPECT_EQ(backupjob.ExecuteTeardownSubJob(), Module::SUCCESS);
}

/*
 * 用例名称：计算任务状态
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, CalculateJobStats)
{
    MOCKER(OBSPlugin::GetFileListInDirectory)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::ReadBackupStatsFromFile)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_subJobInfo = std::make_shared<SubJob>();
    
    EXPECT_EQ(backupjob.CalculateJobStats(), true);
}

/*
 * 用例名称：上报备份完成状态
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ReportBackupCompletionStatus)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::ReadBackupStatsFromFile)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    
    EXPECT_EQ(backupjob.ReportBackupCompletionStatus(), true);
}

static int CopyMetaFileToMetaRepo(
    OBSPlugin::ObjectStorageBackupJob* jobPtr,
    const std::string& prefixSubStr, const std::string& metaPath,
    bool& isCopying,
    bool& isZipSuccess)
{
    isCopying = false;
    isZipSuccess = true;
}

/*
 * 用例名称：执行拷贝元数据子任务
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ExecuteCopyMetaSubJob)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::CopyMetaFileToMetaRepo)
        .stubs()
        .will(invoke(CopyMetaFileToMetaRepo));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    OBSPlugin::ObjectStorageBackupSubJob subJob;
    subJob.prefixInfo.emplace_back(OBSPlugin::PrefixInfo());
    
    EXPECT_EQ(backupjob.ExecuteCopyMetaSubJob(subJob), Module::SUCCESS);
}

/*
 * 用例名称：拷贝元数据文件到meta仓
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, CopyMetaFileToMetaRepo)
{
    MOCKER(Module::runShellCmdWithOutput)
        .stubs()
        .will(returnValue(0));
    MOCKER_CPP(&OBSPlugin::CheckAndDeleteFiles)
        .stubs()
        .will(ignoreReturnValue());

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    std::string prefixSubStr;
    bool isCopying;
    bool isZipSuccess;

    EXPECT_EQ(backupjob.CopyMetaFileToMetaRepo(prefixSubStr, "metaPath", isCopying, isZipSuccess), Module::SUCCESS);
}

/*
 * 用例名称：后置任务主流程
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, PostJobInner)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::InitJobInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetSharedResources)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::PostReportCopyAdditionalInfo)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::DeleteSharedResources)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::RemoveCacheDirectories)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();

    EXPECT_EQ(backupjob.PostJobInner(), Module::SUCCESS);
}

/*
 * 用例名称：清理cache目录
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, RemoveCacheDirectories)
{
    MOCKER(OBSPlugin::Remove)
        .stubs()
        .will(returnValue(true));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();

    EXPECT_NO_THROW(backupjob.RemoveCacheDirectories());
}

/*
 * 用例名称：上报副本信息
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, PostReportCopyAdditionalInfo)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::BuildCopyRepositories)
        .stubs()
        .will(ignoreReturnValue());
    MOCKER(JobService::ReportCopyAdditionalInfo)
        .stubs()
        .will(ignoreReturnValue());
    MOCKER(JsonFileTool::ReadFromFile<OBSPlugin::BackupObjectInfosInCopy>)
        .stubs()
        .will(returnValue(true));
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    backupjob.m_jobResult = AppProtect::JobResult::type::SUCCESS;
    backupjob.m_protectedOBS.obsProtectSubObjectList.emplace_back(OBSPlugin::OBSProtectSubObject());

    EXPECT_EQ(backupjob.PostReportCopyAdditionalInfo(), true);
}

/*
 * 用例名称：构建
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, BuildCopyRepositories)
{
    MOCKER_CPP(&Module::ConfigReader::getInt)
        .stubs()
        .will(returnValue(0));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    StorageRepository storageRepository;
    backupjob.m_multiDataFsList.emplace_back(storageRepository);
    std::vector<StorageRepository> repositories;

    EXPECT_NO_THROW(backupjob.BuildCopyRepositories(repositories));
}

/*
 * 用例名称：上报扫描模块运行信息
 * 前置条件：无
 * check点：返回成功
 */
TEST_F(ObjectStorageBackupJobTest, ReportScanRunningStatus)
{
    MOCKER(OBSPlugin::GetFileListInDirectory)
        .stubs()
        .will(returnValue(true));
    MOCKER(JsonFileTool::ReadFromFile<OBSPlugin::ObjectStorageNativeScanStatistics>)
        .stubs()
        .will(returnValue(true));
    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(ignoreReturnValue());
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    EXPECT_EQ(backupjob.ReportScanRunningStatus(), true);
}

TEST_F(ObjectStorageBackupJobTest, WriteBackupObjectInfoToFile)
{
    MOCKER(OBSPlugin::CreateDirectory)
        .stubs()
        .will(returnValue(true));
    MOCKER(JsonFileTool::WriteToFile<OBSPlugin::BackupObjectInfosInCopy>)
        .stubs()
        .will(returnValue(true));
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    OBSPlugin::BackupObjectInfosInCopy backupObjectInfos;
    EXPECT_EQ(backupjob.WriteBackupObjectInfoToFile(backupObjectInfos), true);
    OBSPlugin::BackupObjectInfo backupObjectInfo;
    backupObjectInfos.objectInfos.push_back(backupObjectInfo);
    EXPECT_EQ(backupjob.WriteBackupObjectInfoToFile(backupObjectInfos), false);
    backupjob.m_backupObjectInfoFilePath = "path";
    EXPECT_EQ(backupjob.WriteBackupObjectInfoToFile(backupObjectInfos), true);
}

TEST_F(ObjectStorageBackupJobTest, ReportScannerCompleteStatus)
{
    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(ignoreReturnValue());
    OBSPlugin::ObjectStorageNativeScanStatistics scanStatistics;
    scanStatistics.m_totFailedFiles = 1;
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    EXPECT_NO_THROW(backupjob.ReportScannerCompleteStatus(scanStatistics));
    scanStatistics.m_totFailedFiles = 0;
    EXPECT_NO_THROW(backupjob.ReportScannerCompleteStatus(scanStatistics));
}

TEST_F(ObjectStorageBackupJobTest, FillMonitorScannerVarDetails)
{
    std::vector<SCANNER_STATUS> scanStatusList = {
        SCANNER_STATUS::FAILED, SCANNER_STATUS::ABORT_IN_PROGRESS, SCANNER_STATUS::ABORTED,
        SCANNER_STATUS::SCAN_READ_COMPLETED, SCANNER_STATUS::CTRL_DIFF_IN_PROGRESS,
        SCANNER_STATUS::SECONDARY_SERVER_NOT_REACHABLE, SCANNER_STATUS::PROTECTED_SERVER_NOT_REACHABLE,
        SCANNER_STATUS::ERROR_INC_TO_FULL
    };
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_backupJobPtr = std::make_shared<AppProtect::BackupJob>();
    OBSPlugin::SCANNER_TASK_STATUS scanTaskStatus;
	SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;
    for (auto status : scanStatusList) {
        backupjob.m_scanStatus = status;
        EXPECT_NO_THROW(backupjob.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus,
            jobLogLabel, jobProgress));
    }
}

TEST_F(ObjectStorageBackupJobTest, testCopyPreviousMetaFile)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::IsAggregate)
        .stubs()
        .will(returnValue(false));
        
    MOCKER_CPP(&OBSPlugin::CheckUnzipMetafileSucceed)
        .stubs()
        .will(returnValue(true));
    OBSPlugin::ObjectStorageBackupJob backupjob;
    backupjob.m_scanMetaPath = "/home";
    std::string prefixSubStr = "prefix1";
    std::string metaPath= "metaPath";
    bool isUnzipping = true;
    bool isUnzipSuccess = true;

    EXPECT_EQ(backupjob.CopyPreviousMetaFile(prefixSubStr, metaPath, isUnzipping, isUnzipSuccess), Module::SUCCESS);
}

TEST_F(ObjectStorageBackupJobTest, testGetPrevBackupInfo)
{
    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::IsFullBackup)
        .stubs()
        .will(returnValue(false));

    MOCKER_CPP(&OBSPlugin::ObjectStorageBackupJob::GetPrevBackupCopyInfo)
        .stubs()
        .will(returnValue(false));

    OBSPlugin::ObjectStorageBackupJob backupjob;
    OBSPlugin::ObjectStorageBackupSubJob subJob;
    subJob.prefixInfo.emplace_back(OBSPlugin::PrefixInfo());
    OBSPlugin::PrefixInfo prefixInfo;
    prefixInfo.bucketName = "protectObject.bucketName";
    subJob.prefixInfo.emplace_back(prefixInfo);

    subJob.esn = "esn";
    backupjob.m_metaFsPathMap[subJob.esn] = "dataFsPath";

    EXPECT_EQ(backupjob.GetPrevBackupInfo(subJob), Module::FAILED);
}

TEST_F(ObjectStorageBackupJobTest, CheckAdvParamChanged)
{
    OBSPlugin::ObjectStorageBackupJob backupjob;
    EXPECT_EQ(backupjob.IsContinueOnNodeFailed(), false);
    EXPECT_EQ(backupjob.IsAclTypeChanged(), false);
    EXPECT_EQ(backupjob.IsMultiNodeBackupSwitchChanged(), false);
}